<html>
<head><meta charset="utf-8"><title>~ as bitwise complement? · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html">~ as bitwise complement?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="195482044"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195482044" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195482044">(Apr 27 2020 at 22:17)</a>:</h4>
<p>Now (Rust 1.0 and later) that <code>~</code> is no longer a sigil for a pointer type, does it seem potentially feasible to make <code>~</code> a bitwise complement operator?</p>



<a name="195482071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195482071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195482071">(Apr 27 2020 at 22:17)</a>:</h4>
<p>So that <code>~0</code> and <code>!0</code> would mean the same thing, rather than forcing users to spell bitwise complement using the latter?</p>



<a name="195482170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195482170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195482170">(Apr 27 2020 at 22:18)</a>:</h4>
<p>It's not obvious to me that having both here is worth it</p>



<a name="195482225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195482225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195482225">(Apr 27 2020 at 22:19)</a>:</h4>
<p>It's certainly a minor but non-zero "surface area" increase. On the flipside, <code>!</code> as bitwise complement spends some of Rust's "weirdness budget".</p>



<a name="195482228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195482228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195482228">(Apr 27 2020 at 22:19)</a>:</h4>
<p>This is one of those places where we have the structural-fix on the error and you just apply it and done</p>



<a name="195482270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195482270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195482270">(Apr 27 2020 at 22:19)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125270">scottmcm</span> <a href="#narrow/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F/near/195482228" title="#narrow/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F/near/195482228">said</a>:</p>
<blockquote>
<p>This is one of those places where we have the structural-fix on the error and you just apply it and done</p>
</blockquote>
<p>I'm thinking more about reading code.</p>



<a name="195482342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195482342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195482342">(Apr 27 2020 at 22:20)</a>:</h4>
<p>When I'm reading low-level code, <code>!</code> makes me double-take.</p>



<a name="195482424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195482424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195482424">(Apr 27 2020 at 22:22)</a>:</h4>
<p>Yeah, this is one of those "given a time machine sure" things</p>



<a name="195482487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195482487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195482487">(Apr 27 2020 at 22:22)</a>:</h4>
<p>Oh, certainly. I'm more wondering if it would be sufficiently non-disruptive to be worth doing now.</p>



<a name="195482513"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195482513" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195482513">(Apr 27 2020 at 22:22)</a>:</h4>
<p>Cost: both operators exist and mean the same thing on numbers, so there's a slight surface-area increase. Some churn as people who prefer <code>~</code> convert their code.</p>



<a name="195482529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195482529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195482529">(Apr 27 2020 at 22:23)</a>:</h4>
<p>Benefit: less confused developers from other languages, easier to read code.</p>



<a name="195482533"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195482533" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195482533">(Apr 27 2020 at 22:23)</a>:</h4>
<p>It's a papercut, but a notable one.</p>



<a name="195482547"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195482547" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195482547">(Apr 27 2020 at 22:23)</a>:</h4>
<p>Feels like it could be a lose-lose as "if it's non-disruptive enough to be feasible it's not valuable enough to do"</p>



<a name="195482609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195482609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195482609">(Apr 27 2020 at 22:24)</a>:</h4>
<p>I'm not sure I know what you mean by that.</p>



<a name="195482629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195482629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195482629">(Apr 27 2020 at 22:24)</a>:</h4>
<p>I'm not suggesting a deprecation (at most, an opt-in lint with a rustfix).</p>



<a name="195483441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195483441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195483441">(Apr 27 2020 at 22:35)</a>:</h4>
<p>I guess I'm weakly not a fan if it's just there's two ways to do the same thing.  I might be more interested if there were a migration plan, or a new <code>ops</code> trait that enabled new scenarios, or something like that.</p>
<p>I also feel like having the distinction opens the door for people asking for <code>!a</code> to be able to write <code>a != 0</code> (after an edition change) since <code>!a</code> would no longer be necessary on integers</p>



<a name="195483531"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195483531" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195483531">(Apr 27 2020 at 22:36)</a>:</h4>
<p>I see. Yeah, I'm <em>not</em> suggesting that we repurpose <code>!</code> on integers, or break it.</p>



<a name="195483593"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195483593" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195483593">(Apr 27 2020 at 22:37)</a>:</h4>
<p>I get what you mean, though. If we just make it an alias, then <code>~</code> will also accept <code>bool</code> types.</p>



<a name="195483615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195483615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195483615">(Apr 27 2020 at 22:37)</a>:</h4>
<p>And if we make it a distinct operator, then it'll be a little surprising that <code>Not</code> and <code>Complement</code> on integers both return bitwise complement.</p>



<a name="195485053"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195485053" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195485053">(Apr 27 2020 at 22:57)</a>:</h4>
<p>I think the ship has sailed at this point. People have been writing Rust for 5 years and know what <code>!a</code> means, it would be pointless churn to add a new way of doing the same thing.</p>



<a name="195485496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195485496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195485496">(Apr 27 2020 at 23:02)</a>:</h4>
<p>Current users have been writing Rust for 5 years. New users encounter Rust every day.</p>



<a name="195485515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195485515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195485515">(Apr 27 2020 at 23:02)</a>:</h4>
<p>The latter would have one less unusual thing to discover and trip over.</p>



<a name="195495891"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195495891" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195495891">(Apr 28 2020 at 02:21)</a>:</h4>
<p>but making !a into ~a means that !true is now written as ~true, which is a poor side effect</p>



<a name="195495941"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195495941" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195495941">(Apr 28 2020 at 02:22)</a>:</h4>
<p>and preferring ~a as "normal" supposes that people have a C background that many Rust users don't even have.</p>



<a name="195527029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195527029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> kennytm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195527029">(Apr 28 2020 at 07:23)</a>:</h4>
<p>in terms of weirdness budget, just wanna note that Go uses <code>^1234</code> as the bitwise-NOT operator</p>



<a name="195528512"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195528512" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195528512">(Apr 28 2020 at 07:40)</a>:</h4>
<p><span class="user-mention silent" data-user-id="224471">Lokathor</span> <a href="#narrow/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F/near/195495891" title="#narrow/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F/near/195495891">said</a>:</p>
<blockquote>
<p>but making !a into ~a means that !true is now written as ~true, which is a poor side effect</p>
</blockquote>
<p>That wasn't what I was proposing. I was proposing to keep <code>!</code> and continue using it for bool.</p>



<a name="195529492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195529492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195529492">(Apr 28 2020 at 07:53)</a>:</h4>
<p><span class="user-mention silent" data-user-id="224471">Lokathor</span> <a href="#narrow/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F/near/195495941" title="#narrow/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F/near/195495941">said</a>:</p>
<blockquote>
<p>and preferring ~a as "normal" supposes that people have a C background that many Rust users don't even have.</p>
</blockquote>
<p>I just did a quick language survey. C, Python, JavaScript, Java, Ruby, C#, Swift, POSIX shell, Julia, PHP, SQL.</p>



<a name="195529501"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195529501" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195529501">(Apr 28 2020 at 07:53)</a>:</h4>
<p>All of those use ~ as bitwise complement.</p>



<a name="195588790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195588790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195588790">(Apr 28 2020 at 16:20)</a>:</h4>
<p>Well, even if that's the case, <code>!a</code> for "logical negation" and separately <code>~a</code> for "bitwise compliment" seems like it's burning two operator characters for not much gain, because the logical negation <em>is</em> the bitwise compliment of a 1 bit value, as we all obviously know since we've all used rust for years.</p>



<a name="195595976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195595976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195595976">(Apr 28 2020 at 17:10)</a>:</h4>
<p>I don't really buy that, I think separating the two operations is fine.</p>



<a name="195595990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195595990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195595990">(Apr 28 2020 at 17:10)</a>:</h4>
<p>But I tend to agree it's disruption without much value.</p>



<a name="195596004"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195596004" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195596004">(Apr 28 2020 at 17:10)</a>:</h4>
<p>On the other hand, it's a pretty minor issue.</p>



<a name="195631210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195631210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195631210">(Apr 28 2020 at 21:44)</a>:</h4>
<p>We get a very small number of characters to make operators with. That's a factually true aspect of the ascii character set, which is what people type rust with.</p>
<p>So we have to be careful with how we assign them meaning simply because we don't get too many meanings before turning into Haskell (which many people don't want, but I guess I don't personally mind).</p>



<a name="195633177"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195633177" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195633177">(Apr 28 2020 at 22:00)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F/near/195595976" title="#narrow/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F/near/195595976">said</a>:</p>
<blockquote>
<p>I don't really buy that, I think separating the two operations is fine.</p>
</blockquote>
<p>Just to elaborate on this: in C already you have <code>!x</code> as distinct from <code>~x</code>, and the same is true in Java and numerous other languages. I don't think there would be much expectation that <code>~x</code> applies to boolean values.</p>



<a name="195633291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195633291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195633291">(Apr 28 2020 at 22:01)</a>:</h4>
<p>I think I was responding, in particular, to <a href="#narrow/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F/near/195495891" title="#narrow/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F/near/195495891">this statement</a></p>



<a name="195644496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195644496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195644496">(Apr 29 2020 at 00:03)</a>:</h4>
<p>Now that I've been reminded of it, I do vaguely remember the syntax from Java, though I don't think I ever used it myself.</p>
<p>I mean it's certainly possible to just make both expressions mean the same thing, I guess my point is that you gain <em>nearly</em> nothing at all (new people get used to using <code>!</code> for bit-negate fairly quickly) and it eats a potential operator that we could use on something in the future.</p>
<p>Such as, just to name one random idea based on the other recent zulip topics: having an operator for numbers that just means "losslessly convert this from the type it is to the type i need right now and don't make a big deal about it, or compile error if you can't".</p>



<a name="195653987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195653987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195653987">(Apr 29 2020 at 02:47)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> So, an operator that means <code>.into()</code>?</p>



<a name="195654786"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195654786" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195654786">(Apr 29 2020 at 03:01)</a>:</h4>
<p>Sure, just one idea that was at hand, i bet a lot of people would like operators depending on what they do.</p>



<a name="195793444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195793444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> mark-i-m <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195793444">(Apr 30 2020 at 02:44)</a>:</h4>
<p>I'm on the fence here. I definitely had a very hard time figuring out that <code>!</code> was both logical and bitwise NOT when I first started. Perhaps the documentation is better these days, but I wouldn't mind make the change over an edition boundary, personally.</p>



<a name="195831000"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/%7E%20as%20bitwise%20complement%3F/near/195831000" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/~.20as.20bitwise.20complement.3F.html#195831000">(Apr 30 2020 at 12:22)</a>:</h4>
<p>I thought this was cute when I first came across it, but I don't remember how I did. Certainly now there's a diagnostic if you try to use <code>~</code> suggesting <code>!</code>, but that doesn't help people reading who are more familiar with <code>~</code>. Adding an extra operator just for bitwise complement seems a little excessive, though.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>